const { Schema, model } = require('mongoose')
const {userModel} = require('../models/user.model')

const commentSchema = new Schema({
    body: {
        type: String,
        required: true,
    },
    article: {
        type: String
    },
    author: {
        type: String,
    },
}, { versionKey: false, timestamps: true })

commentSchema.methods.getAuthorInfo = async function(id) {
	const user = await userModel.findById(id);
	return {
		username: user.username,
		id: user._id,
		profile:user.profile
	}
}
const commentModel = model('Comment', commentSchema)

module.exports = {
    commentModel
}